package com.example.demo.thread.thread;

/**
 * @author: htc
 * @date: Created in 13:44 2019/1/7.
 */
public class AtomicityExample {
    private HostInfo hostInfo;

    public void updateHostInfo(String ip, int port){
        //以下操作不是原子操作
        hostInfo.setIp(ip);
        hostInfo.setPort(port);
    }
    
    public void connectToHost(){
        String ip = hostInfo.getIp();
        int port = hostInfo.getPort();
        connectToHost(ip, port);
    }

    private void connectToHost(String ip, int port) {
    }

    public static class HostInfo{
        private String ip;
        private int port;

        public String getIp() {
            return ip;
        }

        public void setIp(String ip) {
            this.ip = ip;
        }

        public int getPort() {
            return port;
        }

        public void setPort(int port) {
            this.port = port;
        }
    }
}

